/*
  store 模块：集中式管理状态数据

  创建store对象，并暴露：
    {
      getState, 读取数据方法
      dispatch, 触发更新流程（reducer -> 更新store -> 重新渲染）
      subscribe 监听状态变化，执行回调函数
    }
*/

import { createStore, applyMiddleware } from "redux";
// https://github.com/reduxjs/redux-thunk
import { thunk } from "redux-thunk";
// https://www.npmjs.com/package/@redux-devtools/extension
import { composeWithDevTools } from "@redux-devtools/extension";
import reducer from "./reducer";

// process.env.NODE_ENV 用来区分环境的值
// development 开发环境
// production 生产环境

// applyMiddleware(thunk) 应用异步中间件：能在redux执行异步操作
const store = createStore(
  reducer,
  process.env.NODE_ENV === "development"
    ? composeWithDevTools(applyMiddleware(thunk))
    : applyMiddleware(thunk)
);

export default store;
